package com.salesmanager.core.modules.cms.common;

import com.salesmanager.core.business.generic.exception.ServiceException;
import com.salesmanager.core.utils.ImageFilePathUtils;

import java.io.InputStream;

/**
 * Created by Liutong on 10/15/15.
 */
public class CmsFileManagerFacade {

    private CmsFileManager cmsFileManager;

    public CmsFileManagerFacade(CmsFileManager cmsFileManager){
        this.cmsFileManager = cmsFileManager;
    }




    /**
     * 上传广告图
     * @param adCode
     * @param imageName
     * @param inputStream
     * @throws ServiceException
     */
    public void uploadAdImageFile(String adCode,String imageName,InputStream inputStream) throws ServiceException{
        String path = ImageFilePathUtils.buildAdImageFilePath(adCode, imageName).substring(1);
        cmsFileManager.put(path,imageName,inputStream);
    }

    /**
     * 删除广告图
     * @param adCode
     * @param imageName
     * @throws ServiceException
     */
    public void removeAdImageFile(String adCode,String imageName) throws ServiceException{
        String path = ImageFilePathUtils.buildAdImageFilePath(adCode, imageName).substring(1);
        cmsFileManager.remove(path,imageName);
    }


    /**
     *上传通知管理图片
     * @param code
     * @param imageName
     * @param inputStream
     * @throws ServiceException
     */
    public void uploadMessageFile(String code,String imageName,InputStream inputStream) throws ServiceException{
        String path = ImageFilePathUtils.buildMessageImageFilePath(code, imageName).substring(1);
        cmsFileManager.put(path,imageName,inputStream);
    }

    /**
     *删除通知管理图片
     * @param adCode
     * @param imageName
     * @throws ServiceException
     */
    public void removeMessageFile(String adCode,String imageName) throws ServiceException{
        String path = ImageFilePathUtils.buildMessageImageFilePath(adCode, imageName).substring(1);
        cmsFileManager.remove(path,imageName);
    }



    /**
     * 上次安卓渠道包
     * @param channelCode 渠道编码
     * @param fileName 文件名称
     * @param inputStream 文件流
     * @throws ServiceException
     */
    public void uploadApkFile(String channelCode,String fileName,InputStream inputStream) throws ServiceException{
        String path = ImageFilePathUtils.buildChannelApkFilePath(channelCode, fileName).substring(1);;
        cmsFileManager.put(path,fileName,inputStream);
    }

    /**
     * 删除安卓渠道包
     * @param channelCode 渠道编码
     * @param fileName 文件名称
     * @throws ServiceException
     */
    public void removeApkFile(String channelCode,String fileName) throws ServiceException{
        String path = ImageFilePathUtils.buildChannelApkFilePath(channelCode, fileName).substring(1);
        cmsFileManager.remove(path,fileName);
    }


    /**
     * 临时存储上传excel文件
     * @param code 渠道编码
     * @param fileName 文件名称
     * @param inputStream 文件流
     * @throws ServiceException
     */
    public void uploadExcelFile(String code,String fileName,InputStream inputStream) throws ServiceException{
        String path = ImageFilePathUtils.buildAppApKFilePath(code, fileName).substring(1);
        cmsFileManager.put(path,fileName,inputStream);
    }

    /**
     * 删除excel文件
     * @param code 渠道编码
     * @param fileName 文件名称
     * @throws ServiceException
     */
    public void removeExcelFile(String code,String fileName) throws ServiceException{
        String path = ImageFilePathUtils.buildAppApKFilePath(code, fileName).substring(1);
        cmsFileManager.remove(path,fileName);
    }


    /**
     * 上传应用图片文件
     * @param appCode 应用编码
     * @param fileName 文件名称
     * @param inputStream 文件流
     * @throws ServiceException
     */
    public void uploadAppImageFile(String appCode,String fileName,InputStream inputStream) throws ServiceException{
        String path = ImageFilePathUtils.buildAppImageFilePath(appCode, fileName).substring(1);
        cmsFileManager.put(path,fileName,inputStream);
    }

    /**
     * 删除应用图片文件
     * @param appCode 应用编码
     * @param fileName 文件名称
     * @throws ServiceException
     */
    public void removeAppImageFile(String appCode,String fileName) throws ServiceException{
        String path = ImageFilePathUtils.buildAppImageFilePath(appCode, fileName).substring(1);
        cmsFileManager.remove(path,fileName);
    }

    /**
     * 上传应用安装包文件
     * @param appCode 应用编码
     * @param fileName 文件名称
     * @param inputStream 文件流
     * @throws ServiceException
     */
    public void uploadAppApkFile(String appCode,String fileName,InputStream inputStream) throws ServiceException{
        String path = ImageFilePathUtils.buildAppApKFilePath(appCode, fileName).substring(1);;
        cmsFileManager.put(path,fileName,inputStream);
    }

    /**
     * 删除应用安装包文件
     * @param appCode 应用编码
     * @param fileName 文件名称
     * @throws ServiceException
     */
    public void removeAppApkFile(String appCode,String fileName) throws ServiceException{
        String path = ImageFilePathUtils.buildAppApKFilePath(appCode, fileName).substring(1);
        cmsFileManager.remove(path,fileName);
    }


}
